//package com.example.basic.window.dialog;
//
//import android.content.res.Resources;
//import android.graphics.Color;
//import android.graphics.PixelFormat;
//import android.text.Editable;
//import android.util.DisplayMetrics;
//import android.util.Log;
//import android.view.Gravity;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.view.WindowManager;
//import android.widget.EditText;
//import android.widget.FrameLayout;
//
//import androidx.annotation.NonNull;
//
//import com.google.android.material.bottomsheet.BottomSheetBehavior;
//
//public class BottomSheetDialog {
//
//    private com.google.android.material.bottomsheet.BottomSheetDialog bottomSheetDialog;
//    private BottomSheetBehavior mDialogBehavior;
//    private WindowManager.LayoutParams wmParams;
//    private WindowManager windowManager;
//    private ViewGroup.MarginLayoutParams layoutParams;
//    private EditText cet;
//
//    @Override
//    protected void initOnCreate() {
//
//        View inflate = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_dialog, null);
//
//        cet = inflate.findViewById(R.id.cet);
//        cet.setText("aaaaaaaaa.apk");
//        cet.setSelectAllOnFocus(true);
//        bottomSheetDialog = new com.google.android.material.bottomsheet.BottomSheetDialog(this, R.style.BottomSheetDialog);
//        bottomSheetDialog.setContentView(inflate);
//        FrameLayout bottomSheet = (FrameLayout) bottomSheetDialog.findViewById(R.id.design_bottom_sheet);
//        bottomSheet.setBackgroundColor(Color.TRANSPARENT);
//        mDialogBehavior = BottomSheetBehavior.from((View) inflate.getParent());
//        mDialogBehavior.setPeekHeight(getWindowHeight());//dialog的高度
//        mDialogBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
//            @Override
//            public void onStateChanged(@NonNull View view, int i) {
////                if (i == BottomSheetBehavior.STATE_HIDDEN) {
////                    bottomSheetDialog.dismiss();
////                    mDialogBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
////                }
//                if (i == BottomSheetBehavior.STATE_DRAGGING || i == BottomSheetBehavior.STATE_SETTLING) {
//                    mDialogBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
//                }
//            }
//            @Override
//            public void onSlide(@NonNull View view, float v) {
//
//                Log.d("xcl_debug", "onSlide: v = " + v);
//            }
//        });
//    }
//
//    @Override
//    protected int setLayoutXmlid() {
//        return R.layout.activity_bottomsheetdialog;
//    }
//
//    public void show(View view) {
//
//        bottomSheetDialog.show();
//    }
//
//    float float_window_type = 1.0f;
//
//    private int x;
//    private int y;
//
//    public void showFloatWindow(View view) {
//
//        windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
//        wmParams = new WindowManager.LayoutParams();
//        wmParams.packageName = getPackageName();
//        wmParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
//                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
//                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
//                | WindowManager.LayoutParams.FLAG_SCALED
//                | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
//                | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
//
////        if (float_window_type == FLOAT_WINDOW_TYPE_DIALOG) {
////            //wmParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
////            wmParams.type = WindowManager.LayoutParams.TYPE_TOAST;
////        } else if (float_window_type == FLOAT_WINDOW_TYPE_ALERT_WINDOW) {
////            //需要权限
////            wmParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
////        }
//
//        //比当前窗口层级小  出不去  1   切出去 再切进来不消失
//        wmParams.type = WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
//        //也是出不去  2    切出去 再切进来不消失
////        wmParams.type = WindowManager.LayoutParams.TYPE_APPLICATION;
//
//        //3   也是出不去   切出去 再切进来消失
////        wmParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
//        //4  也是出不去 切出去 再切进来不消失
////        wmParams.type = WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
//        //99  也是出不去 切出去 再切进来不消失
////        wmParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
//        //1000  也是出不去 切出去 再切进来不消失
////        wmParams.type = WindowManager.LayoutParams.FIRST_SUB_WINDOW;
////        wmParams.type = WindowManager.LayoutParams.LAST_SUB_WINDOW;
//        wmParams.format = PixelFormat.RGBA_8888;
//        wmParams.gravity = Gravity.START | Gravity.TOP;
//
//        wmParams.width = 800;
//        wmParams.height = 800;
//        wmParams.x = 300;
//        wmParams.y = 300;
//
//        View inflate = LayoutInflater.from(this).inflate(R.layout.float_content, null);
//////        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
////        Button button = inflate.findViewById(R.id.bt);
////        layoutParams = (ViewGroup.MarginLayoutParams) button.getLayoutParams();
////        button.setOnTouchListener(new View.OnTouchListener() {
////            @Override
////            public boolean onTouch(View v, MotionEvent event) {
////                switch (event.getAction()) {
////                    case MotionEvent.ACTION_DOWN:
////                        x = (int) event.getRawX();
////                        y = (int) event.getRawY();
////                        break;
////                    case MotionEvent.ACTION_MOVE:
////                        int nowX = (int) event.getRawX();
////                        int nowY = (int) event.getRawY();
////                        int movedX = nowX - x;
////                        int movedY = nowY - y;
////                        x = nowX;
////                        y = nowY;
////                        Log.d("xcl_debug", "onTouch: movedX = " + movedX + " wmParams.x = " + wmParams.x );
////                        layoutParams.leftMargin = layoutParams.leftMargin + movedX;
////                        layoutParams.topMargin = layoutParams.topMargin + movedY;
////
////                        button.setLayoutParams(layoutParams);
////                        // 更新悬浮窗控件布局
//////                        windowManager.updateViewLayout(button, wmParams);
////                        break;
////                    default:
////                        break;
////                }
////                return true;
////            }
////        });
//        windowManager.addView(inflate, wmParams);
//    }
//
//
//    private int getWindowHeight() {
//        Resources res = this.getResources();
//        DisplayMetrics displayMetrics = res.getDisplayMetrics();
//        return displayMetrics.heightPixels/2;
//    }
//
//    @Override
//    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//    }
//
//    @Override
//    public void onTextChanged(CharSequence s, int start, int before, int count) {
//        Log.d("TAG", "onTextChanged: start = " + start + " before = " + before + " count = " + count);
//        cet.setSelection(cet.getText().length() - 4);
//    }
//
//    @Override
//    public void afterTextChanged(Editable s) {
//
//    }
//}
